import { useList } from '../../store/index'


const store = useList()

// //处理级联数据格式(不带群组)
// export const reListGroup = (res) => {
//     // console.log('res.dat',res.data.data)
//     const cascadeDate = res.data.data
//     let arrayData = []
//     if (cascadeDate !== undefined) {
//             let data = {
//                 value: '',
//                 label: '',
//                 children: []
//             }
//             data.label = cascadeDate[0].fullName
//             data.value = cascadeDate[0].id
//             if (cascadeDate[0].children !== undefined && cascadeDate[0].children.length !== 0) {
//                 cascadeDate[0]['children'].forEach(e => {
//                     data.children.push({
//                         value: e['id'],
//                         label: e['fullName'] + `(${e.postName})`
//                     })
//                 })
//             }
//             arrayData.unshift(data)
       
//     }
//     // sessionStorage.setItem('cascadeDate', JSON.stringify(arrayData))
//     store.upCascade(arrayData)
//     return arrayData
// }

//处理级联数据格式(带群组)
export const regroupData = (res) => {
    const cascadeDate = res.data.data
    let arrayData = []
   
    if (cascadeDate !== undefined) {
        cascadeDate.forEach(item => {
            let data = {
                value: '',
                label: '',
                children: []
            }
            data.label = item.fullName
            data.value = item.id
            if (item.children !== undefined && item.children.length !== 0) {
                item['children'].forEach(e => {
                    data.children.push({
                        value: e['id'],
                        // label: e['fullName'] + `(${e.postName})`
                        label: e['fullName']
                    })
                })
            }
            arrayData.unshift(data)
        })
       
    }
    // sessionStorage.setItem('cascadeDate', JSON.stringify(arrayData))
    store.upCascade(arrayData)
    return arrayData
}


//群组数据修改
export const groupPersons = (value) => {
    let data = []
    console.log(value.length, 'value')
    value.forEach(e => {
        data.push({
            empId: `${e.data.value}`,
            empName: `${e.data.label}`,
        })
    })
    return data
}

// //查看回显
// export const detailEcho = (val) => {
//     let data1 = []
//     let data2 = []
//     val.files.forEach(e => {
//         let obj = {}
//         obj.fileUrl = `${e.fileUrl}` + `${e.fileName}`
//         obj.fileUrl = obj.fileUrl.replace(undefined, '')
//         data1.push(obj)
//     })
//     val.images.forEach(e => {
//         let obj = {}
//         obj.imageUrl = `${e.imageUrl}` + `${e.imageName}`
//         obj.imageUrl = obj.imageUrl.replace(undefined, '')
//         data2.push(obj)
//     })
//     val.files.splice(0, val.files.length)
//     val.images.splice(0, val.images.length)
//     val.files = data1
//     val.images = data2
//     return val
// }

// //预览数据处理
// export const previewData = (val) => {
//     let data = []
//     val.forEach(e => {
//         data.push(Object.values(e))
//     })
//     return data
// }

